package com.service.impl;

import com.dao.RbacRoleDao;
import com.entity.RbacRole;
import com.entity.ResponseEntity;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.service.RbacRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class RbacRoleServiceImpl implements RbacRoleService {
    @Autowired
    RbacRoleDao rbacRoleDao;

    @Autowired
    RedisTemplate redisTemplate;
    @Override
    public String findByAccount(String account) {
        String role = rbacRoleDao.findByAccount(account);
        return role;
    }

    @Override
    public ResponseEntity findAll() {
        List<RbacRole> list =  rbacRoleDao.findAll();
        return new ResponseEntity(200,"成功找到",list);
    }

    @Override
    public ResponseEntity findAll(int currentPage, int pageSize) {
        PageHelper.startPage(currentPage,pageSize);
        List<RbacRole> list = rbacRoleDao.findAll();
        PageInfo info = new PageInfo<>(list);
        return new ResponseEntity<>(200,"成功找到角色信息",info);
    }

    @Override
    public ResponseEntity findRoles(int roleId) {
        List<Integer> checked = rbacRoleDao.findRoles(roleId);
        return new ResponseEntity<>(200,"执行成功",checked);
    }

    @Override
    @Transactional
    public ResponseEntity changeMenus(int[] roles,int roleId) {
        int i = rbacRoleDao.saveChangeMenus(roles,roleId);
        if (i>0){
            return new ResponseEntity<>(200,"成功更新权限菜单数据",null);
        }
        return ResponseEntity.FAIL;
    }
}
